<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class model_gopy extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }

    public function layChuDe($nguoixem) {
    	$this->db->get('gopy');
    	$this->db->from('gopy');
        $this->db->or_like('nguoixem', 'tất cả');
        $this->db->or_like('nguoixem', $nguoixem); 
        $this->db->order_by("codinh", "desc");
        $this->db->order_by("binhluancuoi", "desc"); 
        $query = $this->db->get();
        return $query->result();
    }

    public function layShoutBox() {
        $this->db->get('gopy_shoutbox');
        $this->db->from('gopy_shoutbox');
        $query = $this->db->get();
        return $query->result();
    }

    public function luunoidungshoutbox($data){
        $this->db->insert('gopy_shoutbox', $data);
    }

    public function layTieuDeGopY($magopy) {
        $this->db->select('tieude');
        $this->db->from('gopy');
        $this->db->where('magopy', $magopy);
        $query = $this->db->get();
        return $query->result();
    }

    public function layChiTietGopY($magopy) {
        $this->db->get('gopy_chitiet');
        $this->db->from('gopy_chitiet');
        $this->db->where('magopy', $magopy);
        $this->db->order_by("thoigiantao", "asc");
        $query = $this->db->get();
        return $query->result();
    }

    public function luutraloigopy($data){
        $this->db->insert('gopy_chitiet', $data);
    }

    public function laymagopycuoi(){
        $this->db->get('gopy', 1);
        $this->db->from('gopy');
        $this->db->order_by("magopy", "desc");
        $query = $this->db->get();
        return $query->result();
    }

    public function luutaogopy($data){
        $this->db->insert('gopy', $data);
    }

    public function timtheochude($chudetim, $nguoixem) {
        $this->db->get('gopy');
        $this->db->from('gopy');
        $this->db->like('tieude', $chudetim);
        $this->db->like('nguoixem', 'tất cả');
        $this->db->or_like('nguoixem', $nguoixem);
        $this->db->order_by("codinh", "desc");
        $this->db->order_by("binhluancuoi", "desc");
        $query = $this->db->get();
        return $query->result();
    }
}